import chalk from "chalk-web";

class DevTool {
  debug = false;
  filters = {
    info: true,
    warn: true,
    error: true,
    log: true,
    success: true,
  };
  constructor(debug: boolean, filters: any = {}) {
    this.debug = debug;
    Object.assign(this.filters, filters);
  }

  error(...args: any) {
    if (!this.debug || !this.filters.info) return;
    chalk("red", "来自于DEVTOOL ❌:", ...args);
  }

  warn(...args: any) {
    if (!this.debug || !this.filters.warn) return;
    chalk("orange", "来自于DEVTOOL ⚠️:", ...args);
  }

  info(...args: any) {
    if (!this.debug || !this.filters.info) return;
    chalk("lightblue", "来自于DEVTOOL 📘:", ...args);
  }

  success(...args: any) {
    if (!this.debug || !this.filters.success) return;
    chalk("green", "来自于DEVTOOL ✅:", ...args);
  }

  log(...args: any) {
    if (!this.debug || !this.filters.log) return;
    chalk("purple", "来自于DEVTOOL 📜:", ...args);
  }
}

export const devtool = new DevTool(true);
